#include <stdio.h>

#define M 10
#define N 5

// 计算每个学生的平均分
void Averages1(float grades[][N]) {
    for (int i = 0; i < M; i++) {
        float sum = 0.0;
        for (int j = 0; j < N; j++) {
            sum += grades[i][j];
        }
        float average = sum / N;
        printf("学生 %d 平均分: %.2f\n", i+1, average);
    }
}

// 计算每门课程的平均分
void Averages2(float grades[][N]) {
    for (int j = 0; j < N; j++) {
        float sum = 0.0;
        for (int i = 0; i < M; i++) {
            sum += grades[i][j];
        }
        float average = sum / M;
        printf("课程 %d 平均分: %.2f\n", j+1, average);
    }
}

// 找出所有分数中的最高分数所对应的学生和课程
void high(float grades[][N]) {
    float highest = 0;
    int i,j;
    for (i = 0; i < M; i++) {
        for (j = 0; j < N; j++) {
            if (grades[i][j] > highest) {
                highest = grades[i][j];
            }
        }
    }
    printf("最高分%.2f 是学生 %d 的课程 %d\n", highest, i+1,j+1);
}

// 计算学生的平均分方差
float fangcha(float grades[][N]) {
    float sum = 0.0;
    float studentAverages[M];
    for (int i = 0; i < M; ++i) {
        float Sum = 0.0;
        for (int j = 0; j < N; ++j) {
            Sum += grades[i][j];
        }
        studentAverages[i] = Sum / N;
        sum += studentAverages[i];
    }
    float mean = sum / M;
    float variance = 0.0;
    for (int i = 0; i < M; ++i) {
        variance += (studentAverages[i] - mean) * (studentAverages[i] - mean);
    }
    variance /= M;
    return variance;
}

int main() {
    float grades[M][N];

    // 输入学生成绩
    printf("输入学生和成绩:\n");
    for (int i = 0; i < M; i++) {
        printf("学生 %d:\n", i+1);
        for (int j = 0; j < N; j++) {
            printf("成绩 %d: ", j+1);
            scanf("%f", &grades[i][j]);
        }
    }

    // 调用各函数
    Averages1(grades);
    Averages2(grades);
    high(grades);
    float variance =fangcha(grades);
    printf("平均分方差: %.2f\n", variance);

    return 0;
}